/*
 * SelectScheduleTypeDialog.java
 *
 * Created on 6 de abril de 2009, 15:44
 */

package ubadbtools.recoveryLogAnalyzer.gui.forms;

import java.awt.Frame;
import java.util.Set;

import ubadbtools.recoveryLogAnalyzer.logRecords.CheckPointEndLogRecord;
import ubadbtools.recoveryLogAnalyzer.logRecords.RecoveryLogRecord;

@SuppressWarnings("serial")
public class EditLogRecordDialog extends javax.swing.JDialog {
    
	//[start] Atributos
	private RecoveryLogRecord logRecord = null;
	private Set<String> transactions;
	private Set<String> items;
	private Frame parent;
	//[end]
	
	//[start] Constructor
    public EditLogRecordDialog(java.awt.Frame parent, boolean modal, Set<String> transactions, Set<String> items)
    {
        super(parent, modal);
        initComponents();
        
        this.transactions = transactions;
        this.items = items;
        this.parent = parent;
    }
    //[end]
    
    //[start] showDialog
    public static RecoveryLogRecord showDialog(Frame parent, Set<String> transactions, Set<String> items)
    {
    	EditLogRecordDialog dialog = new EditLogRecordDialog(parent, true, transactions, items);
        dialog.setVisible(true);
        
        return dialog.logRecord;
    }
    //[end]
    
    //[start] InitComponents (AUTO-GENERATED)
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rbgActionType = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        rbStart = new javax.swing.JRadioButton();
        rbUpdate = new javax.swing.JRadioButton();
        rbCommit = new javax.swing.JRadioButton();
        rbCheckPointStart = new javax.swing.JRadioButton();
        rbCheckPointEnd = new javax.swing.JRadioButton();
        jLabel2 = new javax.swing.JLabel();
        butCancelar = new javax.swing.JButton();
        butAceptar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        rbgActionType.add(rbStart);
        rbStart.setSelected(true);
        rbStart.setText("Start"); // NOI18N
        rbStart.setName("rbStart"); // NOI18N

        rbgActionType.add(rbUpdate);
        rbUpdate.setText("Update"); // NOI18N
        rbUpdate.setName("rbUpdate"); // NOI18N

        rbgActionType.add(rbCommit);
        rbCommit.setText("Commit"); // NOI18N
        rbCommit.setName("rbCommit"); // NOI18N

        rbgActionType.add(rbCheckPointStart);
        rbCheckPointStart.setText("CheckPoint Start"); // NOI18N
        rbCheckPointStart.setName("rbCheckPointStart"); // NOI18N
        
        rbgActionType.add(rbCheckPointEnd); 
        rbCheckPointEnd.setText("CheckPoint End"); // NOI18N
        rbCheckPointEnd.setName("rbCheckPointEnd"); // NOI18N        
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(rbStart)
                    .addComponent(rbCommit)
                    .addComponent(rbUpdate)
                    .addComponent(rbCheckPointStart)
                    .addComponent(rbCheckPointEnd))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(rbStart)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbUpdate)                
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbCheckPointStart)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbCheckPointEnd)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                                
                .addComponent(rbCommit, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setText("Tipo de registro"); // NOI18N

        butCancelar.setText("Cancelar"); // NOI18N
        butCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                butCancelarMouseClicked(evt);
            }
        });

        butAceptar.setText("Aceptar"); // NOI18N
        butAceptar.setName("jButton1"); // NOI18N
        butAceptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                butAceptarMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(butAceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(butCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(56, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(47, 47, 47)))
                .addGap(14, 14, 14))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(butCancelar)
                    .addComponent(butAceptar))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
	//[end]
    
    //[start] Eventos
    private void butAceptarMouseClicked(java.awt.event.MouseEvent evt)
    {//GEN-FIRST:event_butAceptarMouseClicked

    	// Genero el registro de log segun los valores en los controles del dialogo
    	
    	if(rbStart.isSelected())
    		logRecord = StartLogRecordDialog.showDialog(parent, transactions);
    	else if(rbCommit.isSelected())
    		logRecord = CommitLogRecordDialog.showDialog(parent, transactions);
    	else if(rbCheckPointStart.isSelected())
    		logRecord = StartCheckpointLogRecordDialog.showDialog(parent, transactions);
    	else if(rbCheckPointEnd.isSelected())
    		logRecord = new CheckPointEndLogRecord();
    	else if(rbUpdate.isSelected())
    		logRecord = UpdateLogRecordDialog.showDialog(parent, transactions,items);   	
    	this.setVisible(false);
    }//GEN-LAST:event_butAceptarMouseClicked

    private void butCancelarMouseClicked(java.awt.event.MouseEvent evt)
    {//GEN-FIRST:event_butCancelarMouseClicked
        this.setVisible(false);
    }//GEN-LAST:event_butCancelarMouseClicked
    //[end]

    //[start] Variables Form (AUTO-GENERATED)
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butAceptar;
    private javax.swing.JButton butCancelar;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton rbCommit;
    private javax.swing.JRadioButton rbCheckPointStart;
    private javax.swing.JRadioButton rbCheckPointEnd;
    private javax.swing.JRadioButton rbStart;
    private javax.swing.JRadioButton rbUpdate;
    private javax.swing.ButtonGroup rbgActionType;
    // End of variables declaration//GEN-END:variables
    //[end]
}
